import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:qianyi/entity/home/Comment.dart';
import 'package:qianyi/state/token.dart';
import 'package:qianyi/utils/throttle.dart';
import 'package:qianyi/view_model/home/comment_view_model.dart';
import 'package:qianyi/wcao/ui/theme.dart';

import '../network/http_config.dart';
import '../network/http_manager.dart';


class DialogDelegate {
  static void showBottomPop(BuildContext context, String title, Comment comment, CommentViewModel commentViewModel,
      {Widget? child, bool isScrollControlled = false, double height = double.infinity}) {
    TokenController tokenController = Get.find();
    TextEditingController textcontroller = TextEditingController();
    bool isSend = false;
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        isScrollControlled: isScrollControlled,
        builder: (BuildContext context) {
          return Container(
            height: 350,
            decoration: const ShapeDecoration(
              color: Color(0xffffffff),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(5),
                    topRight: Radius.circular(5)),
              ),
            ),
            child: Column(
              children: [

            Stack(
              alignment: AlignmentDirectional.topEnd,
              children: <Widget>[
                TextField(
                  controller: textcontroller,
                  maxLines: 5,
                  decoration: InputDecoration(

                    hintText: '留下你的足迹',
                    border: OutlineInputBorder(),
                    contentPadding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 20),

                  ),
                ),
                Positioned(
                  right: 0,
                  bottom: 0,
                  child:  Container(
                    width: 50,
                    height: 30,
                    margin: EdgeInsets.all(2), // 内边距
                    decoration: BoxDecoration(
                      border: Border.all(
                        color: WcaoTheme.primary, // 边框颜色
                        width: 0.5, // 边框宽度
                      ),
                      borderRadius: BorderRadius.circular(14.0), // 圆角大小
                    ),
                    child: ConstrainedBox(
                      constraints: BoxConstraints(

                      ),
                      child: GestureDetector(
                        onTap: () async {
                          HudUtil.showSend();

                          String uid =  await tokenController.getUid();
                          Map<String,dynamic> params = {
                            "content":textcontroller.text,
                            "uid":uid,
                            "mid":comment.mid,
                            "pid":comment.id,
                            "replyId":comment.id,
                            "replyUid":comment.uid,
                            "level":2
                          };
                          if(!isSend) {
                            await HttpManager.getInstance().request(url: '/platform/comment/addComment',method: Method.post,params: params).then((value) => {
                              HudUtil.dismiss(),
                              isSend = false,
                              textcontroller.clear(),
                              commentViewModel.onRefresh(),
                              Navigator.pop(context)
                            });
                          }
                        },
                        child: Center(
                          child: Text(
                            "发送",
                            textAlign: TextAlign.center, // 文本居中
                            style: TextStyle(fontSize: 14.7,color: WcaoTheme.primary), // 文本样式
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),




              ],
            ),
          );
        });
  }
  static void showBottomPop2(BuildContext context, String title, Comment comment, CommentViewModel commentViewModel, String pid,
      {Widget? child, bool isScrollControlled = false, double height = double.infinity}) {
    TokenController tokenController = Get.find();
    TextEditingController textcontroller = TextEditingController();
    bool isSend = false;
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.transparent,
        isScrollControlled: isScrollControlled,
        builder: (BuildContext context) {
          return Container(
            height: 350,
            decoration: const ShapeDecoration(
              color: Color(0xffffffff),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(5),
                    topRight: Radius.circular(5)),
              ),
            ),
            child: Column(
              children: [

                Stack(
                  alignment: AlignmentDirectional.topEnd,
                  children: <Widget>[
                    TextField(
                      controller: textcontroller,
                      maxLines: 5,
                      decoration: InputDecoration(

                        hintText: '留下你的足迹',
                        border: OutlineInputBorder(),
                        contentPadding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 20),

                      ),
                    ),
                    Positioned(
                      right: 0,
                      bottom: 0,
                      child:  Container(
                        width: 50,
                        height: 30,
                        margin: EdgeInsets.all(2), // 内边距
                        decoration: BoxDecoration(
                          border: Border.all(
                            color: WcaoTheme.primary, // 边框颜色
                            width: 0.5, // 边框宽度
                          ),
                          borderRadius: BorderRadius.circular(14.0), // 圆角大小
                        ),
                        child: ConstrainedBox(
                          constraints: BoxConstraints(

                          ),
                          child: GestureDetector(
                            onTap: () async {
                              HudUtil.showSend();

                              String uid =  await tokenController.getUid();
                              Map<String,dynamic> params = {
                                "content":textcontroller.text,
                                "uid":uid,
                                "mid":comment.mid,
                                "pid":pid,
                                "replyId":comment.id,
                                "replyUid":comment.uid,
                                "level":2
                              };
                              if(!isSend) {
                                await HttpManager.getInstance().request(url: '/platform/comment/addComment',method: Method.post,params: params).then((value) => {
                                  HudUtil.dismiss(),
                                  isSend = false,
                                  textcontroller.clear(),
                                  commentViewModel.onRefresh(),
                                  Navigator.pop(context)
                                });
                              }
                            },
                            child: Center(
                              child: Text(
                                "发送",
                                textAlign: TextAlign.center, // 文本居中
                                style: TextStyle(fontSize: 14.7,color: WcaoTheme.primary), // 文本样式
                              ),
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),




              ],
            ),
          );
        });
  }


}
